$(function() {
	var $modal = $('#my-modal-loading');
	var query_id = localStorage.getItem("query_id");
	console.log("store_id:" + query_id);
	var urlPath = "http://yx.fxtourong.com/V1/Circle/joinTheWay" + "?store_id=" + query_id;
	var urlPath2 = "http://yx.fxtourong.com/V1/Circle/getJoinWayStatus" + "?store_id=" + query_id;
	
	$modal.modal();
	$.ajax({
			type: "POST",
			url: urlPath2,
			data: {
				token: localStorage.getItem("token")
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				console.log(data);
				var code = data.code;
				console.log(code);
				if(code == "1") {
					var is_pay = data.data.is_pay;
					if(is_pay == "0"){
						$("#allPeople").attr("checked","checked");
					} else {
						$("#masterOnly").attr("checked","checked");
					}
					
				} else {
					alert(data.message + "");
					window.history.back(-1);
				}
			},
			error: function(e){
				$modal.modal('close');
				alert("服务请求异常！")
			}
		});	
	$("input[name='settingtype']").each(function(){
        $(this).click(function(){
            var discount = $(this).val();
            if(discount=="免费加入圈子"){
                $("#div_money").css("display","none");
            } else {
            	$("#div_money").css("display","block");
            }
        });
    });
	$("#saveIt").click(function(){
		var index = 1;
		var perissionStr = $("input[name='settingtype']:checked").val();
		var price = 0;
		if(perissionStr == "免费加入圈子"){
			index = 0;
		} else {
			index = 1;
			price = $("#input_money").val();
		}
		if(index == 1 && price == 0){
			alert("请输入付费金额！");
			return;
		}
		$modal.modal();
		$.ajax({
			type: "POST",														  
			url: urlPath,
			data: {
				token : localStorage.getItem("token"),   
				permissions: index
			},
			dataType: "json",
			success: function(data) {
				$modal.modal('close');
				var code = data.code;
				console.log(code);
				if(code == "1") {
					new Toast({context:$('body'),message:'设置成功'}).show();	
					window.history.back(-1);
				} else {
					alert(data.message + "");									  
				}
				
			},
			error: function(e){													  //错误之后的动作
				$modal.modal('close');
				alert("服务请求异常！");
			}
		});
	});
		

});